import { NextRequest } from "next/server"
export async function POST( request: NextRequest ) {
 const { list } = await request.json()
 const encoder = new TextEncoder()
 const stream = new ReadableStream({
     async start(controller) {
        const messageText = list[list.length - 1].content
        console.log(messageText)
         for (let i = 0; i< messageText.length; i++) {
             await new Promise((resolve) => setTimeout(resolve, 50))
             controller.enqueue(encoder.encode(messageText[i]))
         }
         controller.close()
     }
 })
//  封装好的数据流返回给客户端
 return new Response(stream)
}